package com.test03_类与对象;

/**
 * 成员属性私有化
 */
public class YootkDemo_02 {

    public static void main(String[] args) {
        Book2 book = new Book2();
        book.setTitle("沐言Java");
        book.setAuthor("李兴华");
        // book.setPrice(-79.8);
        book.setPrice(79.8);
        book.getInfo();
    }
}

/**
 * 图书类
 */
class Book2 {
    private String title;   // 图书名称
    private String author;  // 图书作者
    private double price;   // 图书价格

    public void getInfo() {
        System.out.println("图书名称：" + title + "、图书作者：" + author + "、图书价格：" + price);
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        if (price > 0) {
            this.price = price;
        }
    }
}
